﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Scheduler.Data_Access_Layer
{
    /**Class: ErrorLookup
    * @author Daniel Chopson
    * @version 1.0
    * Course : ITEC 4860 Spring 2012
    * Written: March 22, 2012
    *
    * This class translates a SQL error number to a more simplified error code agreed
    * upon by the team.
    *
    * Purpose: To provide error codes for error handling in classes that use the
    * Data_Access_Layer classes
    */

    class ErrorLookup
    {
        //The SQL error number

        private int errorNumberSQL;

        /** Method: ErrorLookup
          * Constructor for this class. Instantiates all class variables
          * @param errorNumberSQL the SQL error number
          */

        public ErrorLookup(int errorNumberSQL)
        {
            this.errorNumberSQL = errorNumberSQL;
        }

        /** Method: returnSimpleError
          * Converts certain SQL error numbers to simplified error codes
          * @return an integer error code
          */

        public int returnSimpleError()
        {
            //Cannot insert duplicate key or key constraint

            if (errorNumberSQL == 2601 || errorNumberSQL == 2627)
            {
                return 8;
            }
            
            //Cannot open user default database. Login failed.

            else if (errorNumberSQL == 4064)
            {
                return 16;
            }

            //Cannot insert due to foreign key constraint
            else if (errorNumberSQL == 547 || errorNumberSQL == 3621)
            {
                return 32;
            }

            //All is well. No errors.

            else
            {
                return 0;
            }
        }
    }
}
